package com.paydemo.pay.task;

import com.paydemo.pay.service.PayOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 支付超时检查定时任务
 */
@Slf4j
@Component
@EnableScheduling
public class PaymentTimeoutTask {

    @Resource
    private PayOrderService payOrderService;

    /**
     * 每5分钟检查一次支付超时订单
     */
    @Scheduled(fixedRate = 300000) // 5分钟执行一次
    public void checkPaymentTimeout() {
        log.info("开始执行支付超时订单检查任务");
        try {
            payOrderService.checkPaymentTimeout();
            log.info("支付超时订单检查任务执行完成");
        } catch (Exception e) {
            log.error("支付超时订单检查任务执行异常", e);
        }
    }
} 